package oa.biz.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oa.biz.EmployeeBiz;
import oa.entity.Employee;
import oa.mapper.EmployeeMapper;

@Service
public class EmployeeBizImpl implements EmployeeBiz {
	@Autowired
	private EmployeeMapper emp;

	@Override
	public Employee fetchByUser(String nr,String password) {
		return emp.fetchByUser(nr,password);
	}

	@Override
	public void updatePassword(String nr,int id) {
		emp.updatePassword(nr,id);

	}

	@Override
	public List<Employee> getAll() {
	List<Employee> employee=emp.getAll();
	for(Employee e:	employee){
		switch (e.getIsManager()) {
		case 1:
			e.setRoleName("部门主管");
			break;
		default:
			e.setRoleName("员工");
			break;
		}
	}
		return employee;
	}

	@Override
	public Employee fetchByid(int id) {
		// TODO Auto-generated method stub
		return emp.fetchByid(id);
	}

	@Override
	public void addEmployee(Employee employee) {
		emp.addEmployee(employee);
		
	}

	@Override
	public void updateEmployee(Employee employee) {
		emp.updateEmployee(employee);
	}

	@Override
	public List<Employee> getAllztree() {
		 List<Employee> employeeList =emp.getAllztree();
		 List<Employee> all = new ArrayList<Employee>();
		 for(Employee e:employeeList){
			 e.setId(e.getId()+100);
			e.setPid(e.getDepartmentId());
			all.add(e);
		 }
		 return all;
	}

}
